<template>
  <div class="page-title">出品查询</div>
  <div class="consult-container">
    <div class="consult-bewtten">
      <div class="consult-tabs">
        <div
          v-for="(item, index) in consultList"
          :key="index"
          @click="onChangeTab(index)"
          :class="{ 'consult-tab': true, active: consultActive == index }"
        >
          {{ item.name }}
        </div>
      </div>
      <div class="cp_continar" @click="toPath">出品汇总打印</div>
    </div>
    <!-- 出品汇总 -->
    <div class="table-main" v-show="consultActive === 0">
      <el-form class="search-form" label-width="auto" :model="searchForm">
        <el-row :gutter="20">
          <el-col :span="5">
            <el-form-item label="出品时间:">
              <el-date-picker
                v-model="searchForm.operDate"
                type="daterange"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                value-format="YYYY-MM-DD HH:mm:ss"
                @change="handleDateChange"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <div class="time-radio">
              <div>
                <el-radio v-model="timeType" label="0">营业日</el-radio>
              </div>
              <div >
                <el-radio v-model="timeType" label="1">自然日</el-radio>
              </div>
            </div>
           
          </el-col>
          <el-col :span="5">
            <el-form-item label="出品点:">
              <el-select v-model="searchForm.goodsPoint" multiple filterable clearable :disabled="searchForm.itemType == 1 || searchForm.itemType == 3" >
                <el-option
                  v-for="item in GetGoodsList"
                  :key="item.code"
                  :value="item.code"
                  :label="item.name"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="商品名称:">
              <el-input
                v-model="searchForm.goodsName"
                placeholder="请输入"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="分类:" class="spe">
              <el-select v-model="searchForm.goodsType" filterable clearable multiple>
                <el-option
                  v-for="item in GoodsTypeList"
                  :key="item.code"
                  :value="item.code"
                  :label="item.name"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <div class="setup-main-item">
              <div class="item-right">
                <el-radio v-model="searchForm.itemType" label="0">仅单品</el-radio>
                <el-radio v-model="searchForm.itemType" label="1">仅套餐</el-radio>
                <el-radio v-model="searchForm.itemType" label="2">单品含套餐</el-radio>
                <el-radio v-model="searchForm.itemType" label="3">单品/套餐</el-radio>
              </div>
            </div>
          </el-col>
          <el-col :span="5">
            <div class="setup-main-item">
              <div class="item-right">
                <el-radio v-model="searchForm.giveType" label="0">全部</el-radio>
                <el-radio v-model="searchForm.giveType" label="1">不含赠送</el-radio>
                <el-radio v-model="searchForm.giveType" label="2">仅赠送</el-radio>
              </div>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="setup-main-item">
              <div class="item-right">
                <el-radio v-model="searchForm.isShowType" label="1">显示分类</el-radio>
                <el-radio v-model="searchForm.isShowType" label="0">不显示分类</el-radio>
              </div>
            </div>
          </el-col>
          <el-col class="action-btn-box" :span="8" style="margin-bottom: 20px;">
            <el-button type="primary" @click="print">打印</el-button>
            <el-button type="primary" @click="handleSearch">查询</el-button>
            <el-button class="reset-btn" @click="handleReset">清空筛选</el-button>
            <el-button type="primary" @click="doExport('hz')">导出Excel</el-button>
          </el-col>
        </el-row>
      </el-form>
      <div class="table-box">
        <div class="total-box">
          <div class="content">
            总金额：<span class="color-FF6A00">{{
              headData.totalAmt ? formatDecimal(headData.totalAmt) : "0"
            }}</span>
          </div>
          <div class="content">
            总数量：<span class="color-FF6A00">{{
              headData.totalQty ? headData.totalQty : "0"
            }}</span>
          </div>
        </div>
        <el-table :data="tableData" stripe v-loading="loading">
          <el-table-column
            prop="goodsName"
            label="商品名称"
            min-width="150px"
          />
          <el-table-column
            prop="goodsCode"
            label="物资编码"
            min-width="150px"
          />
          <el-table-column prop="typeName" label="分类" min-width="130px" />
          <el-table-column prop="uomName" label="单位" min-width="130px" />
          <el-table-column prop="pointName" label="出品点" min-width="130px" />
          <el-table-column
            prop="totalQtys"
            label="销售数量"
            sortable
            min-width="150px"
          />
          <el-table-column
            prop="totalAmts"
            label="销售总金额"
            sortable
            min-width="130px"
          />

          <el-table-column prop="" label="操作" min-width="80px" fixed="right">
            <template #default="scope">
              <el-button class="action-btn" @click="handleDetail(scope.row,searchForm.operDate)">
                查看详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <!-- 出品流水 -->
    <div class="book-main" v-show="consultActive === 1">
      <el-form class="search-form" label-width="auto" :model="searchFormPre">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="选择区域:">
              <el-select v-model="searchFormPre.areaCode" filterable clearable>
                <el-option
                  v-for="item in area_options"
                  :key="item.roomAreaCode"
                  :value="item.roomAreaCode"
                  :label="item.roomAreaName"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="选择桌台:">
              <el-input
                v-model="searchFormPre.roomName"
                placeholder="请选择桌台号"
                readonly
                @click="allTableSelectShow = true"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="点单/收银员:">
              <el-input
                v-model="searchFormPre.userName"
                placeholder="请输入"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="出品点:">
              <el-select v-model="searchFormPre.goodsPoint" filterable clearable>
                <el-option
                  v-for="item in GetGoodsList"
                  :key="item.code"
                  :value="item.code"
                  :label="item.name"
                />
              </el-select>
            </el-form-item>
          </el-col>
          
          <el-col :span="6">
            <el-form-item label="商品名称:">
              <el-input
                v-model="searchFormPre.goodsName"
                placeholder="请输入"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="分类:" class="fl-item">
              <el-select v-model="searchFormPre.goodsType" filterable clearable>
                <el-option
                  v-for="item in GoodsTypeList"
                  :key="item.code"
                  :value="item.code"
                  :label="item.name"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="单号:">
              <el-input
                v-model="searchFormPre.code"
                placeholder="请输入台单号/订单单号"
                clearable
              />
            </el-form-item>
          </el-col>
          
          
          <el-col :span="7">
            <el-form-item label="点单/买单时间:">
              <el-date-picker
                v-model="searchFormPre.operDate"
                type="daterange"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                value-format="YYYY-MM-DD HH:mm:ss"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <div class="time-radio">
              <div>
                <el-radio v-model="timeType" label="0">营业日</el-radio>
              </div>
              <div >
                <el-radio v-model="timeType" label="1">自然日</el-radio>
              </div>
            </div>
           
          </el-col>
          <el-col :span="19"></el-col>
          <el-col class="action-btn-box" :span="5">
            <el-button type="primary" @click="handleSearchPre">查询</el-button>
            <el-button class="reset-btn" @click="handleResetPre">清空筛选</el-button>
            <el-button type="primary" @click="doExport('ls')">导出Excel</el-button>
          </el-col>
        </el-row>
      </el-form>
      <div class="table-box">
        <div class="total-box">
          <div class="content">
            总金额：<span class="color-FF6A00">{{
              headData2.totalAmt ? formatDecimal(headData2.totalAmt) : "0"
            }}</span>
          </div>
          <div class="content">
            总数量：<span class="color-FF6A00">{{
              headData2.totalQty ? headData2.totalQty : "0"
            }}</span>
          </div>
        </div>
        <el-table :data="tableData" stripe v-loading="loading">
          <el-table-column
            prop="goodsName"
            label="商品名称"
            min-width="100px"
          />
          <el-table-column
            prop="goodsCode"
            label="物资编码"
            min-width="100px"
          />
          <el-table-column prop="typeName" label="分类" min-width="60px" />
          <el-table-column prop="uomName" label="单位" min-width="60px" />
          <el-table-column prop="totalQtys" label="数量" min-width="60px" />
          <el-table-column prop="salePrice" label="单价" min-width="60px" />
          <el-table-column prop="totalAmts" label="总金额" min-width="60px" />
          <el-table-column prop="pointName" label="出品点" min-width="60px" />
          <el-table-column prop="roomName" label="桌台" min-width="60px" />
          <el-table-column prop="startTime" label="开台时间" min-width="140px">
            <template #default="scope">
              <span>{{
                dayjs(scope.row.startTime).format("YYYY-MM-DD HH:mm:ss")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="orderUserName" label="点单员" min-width="80px"/>
          <el-table-column prop="startTime" label="点单时间" min-width="140px">
            <template #default="scope">
              <span>{{
                dayjs(scope.row.orderTime).format("YYYY-MM-DD HH:mm:ss")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="payUserName" label="收银员" min-width="80px" >
          <template #default="scope">
              <span>{{scope.row.payUserName? scope.row.payUserName:'--'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="payTime" label="买单时间" min-width="140px">
            <template #default="scope">
              <span>{{scope.row.payTime? dayjs(scope.row.payTime).format("YYYY-MM-DD HH:mm:ss"):'--'}}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="orderRecords-container-footer">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="pageSize"
        layout="total, prev, pager, next,sizes, jumper"
        :total="total"
      ></el-pagination>
      <button class="footer-button">确定</button>
    </div>
    <AllTableSelect
      v-model="allTableSelectShow"
      v-if="allTableSelectShow"
      :areaCode="searchFormPre.areaCode" 
      @cancel="allTableSelectShow = false"
      @confirm="selectTable"
    />
  </div>
</template>
<script setup>
import dayjs from "dayjs";
import PreOrderTable from "@/views/components/PreOrderTable.vue";
import AllTableSelect from "@/views/components/AllTableSelect.vue";
import { formatDecimal } from "@/utils/chenhao";
import Api from "@/api";
import ls from "@/lib/ls";
import { transformWorkTime } from "@/utils/chenhao.js";
import useConfigStore from "@/store/config";
const configStore = useConfigStore();
console.log(configStore.shopInfo);

const orgStartTime = configStore.shopInfo.orgReportStartTime //报表开始时间;
const orgEndTime = configStore.shopInfo.orgReportEndTime //报表结束时间;
// const orgStartTime = configStore.shopInfo.orgStartTime //营业开始时间;
// const orgEndTime = configStore.shopInfo.orgEndTime //营业结束时间;
const router = useRouter();

// --------------------------------------------------------------- 头部配置 ---------------------------------------------------------------------
let searchFormPre = ref({});

const consultActive = ref(0);
const consultList = [
  {
    name: "出品汇总查询",
  },
  {
    name: "出品流水查询",
  },
];

const timeType = ref('0')


//获取分类列表
const GoodsTypeList = ref("");
const GetGoodsTypeOrg = () => {
  Api.Common.PcObjProcess.Do({
    functionName: "GetGoodsType",
    orgCode: "0004",
    contentData: "",
  }).then((res) => {
    GoodsTypeList.value = res.result;
  });
};

//获取出品点
const GetGoodsList = ref("");
const GetGoodsPoint = () => {
  Api.Common.PcObjProcess.Do({
    functionName: "GetGoodsPoint",
    orgCode: "0004",
    contentData: "",
  }).then((res) => {
    console.log(res, "出品点===============================");
    GetGoodsList.value = res.result;
  });
};

const onChangeTab = (index) => {
  if (consultActive.value === index) {
    return;
  }
  currentPage.value = 1;
  consultActive.value = index;
  if (index === 0) {
    getTableData();
  }
  if (index === 1) {
    getTableDataPre();
  }
  console.log("onChangeTab...");
};

// 点击选择桌台
const allTableSelectShow = ref(false);
// 选中桌台
const selectTable = (data) => {
  if (data.name) {
    console.log(data);
    searchForm.value.roomCode = data.code;
    searchForm.value.roomName = data.name;

    searchFormPre.value.roomCode = data.code;
    searchFormPre.value.roomName = data.name;

    allTableSelectShow.value = false;
  } else {
    ElNotification({
      title: "提示",
      message: "请选择桌号",
      type: "warning",
    });
  }
};




// 获取区域OPTIONS
let area_options = ref([]);
const get_area_options = (params) => {
  Api.Common.PcObjProcess.Do({
    functionName: "getRoomArea",
    orgCode: "0004",
    contentData: "",
  }).then((res) => {
    console.log("获取区域OPTIONS res :>> ", res);
    area_options.value = res.result;
  });
};
get_area_options();

let loading = ref(false);
let searchForm = ref({
  itemType:'3',
  giveType:'0',
  isShowType:'1'
});

watch(() => searchForm.value.itemType, (newValue, oldValue) => {
    console.log(newValue);
    if (newValue == '1' || newValue == '3') {
      searchForm.value.goodsPoint = ''
        // console.log(navBtnList.value);
       
    }
})
// 搜索
const handleSearch = (params) => {
  currentPage.value = 1;
  getTableData();
};
// 重置
const handleReset = (params) => {
  searchForm.value = {};
  headData.value ={};
  handleSearch();
};
// 查询表格数据
let headData = ref({
  totalAmt: "",
  totalQty: "",
});

let headData2 = ref({
  totalAmt: "",
  totalQty: "",
});
let tableData = ref([{}]);
let currentPage = ref(1);
let pageSize = ref(10);
let total = ref(0);

// 修改分页一页多少条 (通用分页)
const handleSizeChange = (val) => {
  console.log("handleSizeChange...");
  currentPage.value = 1;
  pageSize.value = val;
  if (consultActive.value === 0) {
    getTableData();
  }
  if (consultActive.value === 1) {
    getTableDataPre();
  }
  console.log("handleSizeChange...");
};
// 修改分页第几页 (通用分页)
const handleCurrentChange = (val) => {
  currentPage.value = val;
  if (consultActive.value === 0) {
    getTableData();
  }
  if (consultActive.value === 1) {
    getTableDataPre();
  }
  console.log("handleCurrentChange...");
};

const getTableData = (user) => {
  let query = {
    ...searchForm.value,
    pageIndex: currentPage.value,
    pageSize: pageSize.value,
  };


  if (query.operDate && query.operDate.length > 1) {
    let startDate = query.operDate[0].split(' ')[0]; // 提取第一个元素的日期部分
    let endDate = query.operDate[1].split(' ')[0];   // 提取第二个元素的日期部分
    if(startDate == endDate){ // 如果日期相同 加一天  如26-26 变成26-27
      const date = new Date(endDate);
      date.setDate(date.getDate() + 1);
      const newDate = date.toISOString().split('T')[0]; 
      endDate = newDate
    }
    if(timeType.value == '0'){
      const fullStartDateTime = `${startDate} ${orgStartTime}`;
      const fullEndDateTime = `${endDate} ${orgEndTime}`;
      query.operDate = [fullStartDateTime,fullEndDateTime]
    }else if(timeType.value == '1'){{
      const fullStartDateTime = `${startDate} ${'00:00:00'}`;
      const fullEndDateTime = `${endDate} ${'00:00:00'}`;
      query.operDate = [fullStartDateTime,fullEndDateTime]
    }}
    query.startTime = query.operDate[0];
    query.endTime = query.operDate[1];
  }

  console.log("查询前的query :>> ", query);
  loading.value = true;
  // return
  if(query.goodsType){
    query.goodsType = query.goodsType.join(',')
  }
  if(query.goodsPoint){
    query.goodsPoint = query.goodsPoint.join(',')
  }
  Api.Common.PcObjProcess.Do({
    functionName: "GetPointGoodList",
    orgCode: "0004",
    contentData: query,
  }).then((res) => {
    console.log("查询订单table res :11111111>> ", res);
    loading.value = false;
    tableData.value = res.data.list;
    console.log(tableData, "tableData");
    total.value = res.totalCount;
    headData.value = res.data;
    // if ((res.data.totalAmt || res.data.totalAmt == 0) && (res.data.totalQty || res.data.totalQty == 0)) {
    //   headData.value = res.data;
    // }
  });
};

// 点击查看详情
const handleDetail = (item,operDate) => {
  searchFormPre.value.operDate = operDate
  searchFormPre.value.goodsName = item.goodsName
  consultActive.value = 1;
  getTableDataPre()
};

const toPath = () => {
     router.push({
                path: '/cashier/printProduction'
      })
}

const print = ()=>{
  let query = {
    ...searchForm.value,
    pageIndex: currentPage.value,
    pageSize: pageSize.value,
  };
  if (query.operDate && query.operDate.length > 1) {
    let startDate = query.operDate[0].split(' ')[0]; // 提取第一个元素的日期部分
    let endDate = query.operDate[1].split(' ')[0];   // 提取第二个元素的日期部分
    console.log(startDate,endDate);

    if(startDate == endDate){ // 如果日期相同 加一天  如26-26 变成26-27
      const date = new Date(endDate);
      date.setDate(date.getDate() + 1);
      const newDate = date.toISOString().split('T')[0]; 
      endDate = newDate
    }

    if(timeType.value == '0'){
      const fullStartDateTime = `${startDate} ${orgStartTime}`;
      const fullEndDateTime = `${endDate} ${orgEndTime}`;
      query.operDate = [fullStartDateTime,fullEndDateTime]
    }else if(timeType.value == '1'){{
      const fullStartDateTime = `${startDate} ${'00:00:00'}`;
      const fullEndDateTime = `${endDate} ${'00:00:00'}`;
      query.operDate = [fullStartDateTime,fullEndDateTime]
    }}
    query.startTime = query.operDate[0];
    query.endTime = query.operDate[1];
  }
  

  console.log("查询前的query :>> ", query);
  // return
  if(query.goodsType){
    query.goodsType = query.goodsType.join(',')
  }
  if(query.goodsPoint){
    query.goodsPoint = query.goodsPoint.join(',')
  }
  Api.Common.PcObjProcess.Do({
    functionName: "GetPointGoodPrint",
    orgCode: "0004",
    contentData: query,
  }).then((res) => {
    console.log(res)
    ElNotification({title: '提示',message: "打印成功", type: 'success'});
  });
}

// 搜索
const handleSearchPre = (params) => {
  currentPage.value = 1;
  getTableDataPre();
};
// 重置
const handleResetPre = (params) => {
  searchFormPre.value = {};
  headData2.value ={};
  handleSearchPre();
};

// 获取出品流水
const getTableDataPre = () => {
  console.log("查询前的query :>> ", searchFormPre.value);
  let query = {
    ...searchFormPre.value,
    pageIndex: currentPage.value,
    pageSize: pageSize.value,
  };
  if (query.operDate && query.operDate.length > 1) {
    let startDate = query.operDate[0].split(' ')[0]; // 提取第一个元素的日期部分
    let endDate = query.operDate[1].split(' ')[0];   // 提取第二个元素的日期部分
    console.log(startDate,endDate);

    if(startDate == endDate){ // 如果日期相同 加一天  如26-26 变成26-27
      const date = new Date(endDate);
      date.setDate(date.getDate() + 1);
      const newDate = date.toISOString().split('T')[0]; 
      endDate = newDate
    }

    if(timeType.value == '0'){
      const fullStartDateTime = `${startDate} ${orgStartTime}`;
      const fullEndDateTime = `${endDate} ${orgEndTime}`;
      query.operDate = [fullStartDateTime,fullEndDateTime]
    }else if(timeType.value == '1'){{
      const fullStartDateTime = `${startDate} ${'00:00:00'}`;
      const fullEndDateTime = `${endDate} ${'00:00:00'}`;
      query.operDate = [fullStartDateTime,fullEndDateTime]
    }}
    query.startTime = query.operDate[0];
    query.endTime = query.operDate[1];
  }
  loading.value = true;
  Api.Common.PcObjProcess.Do({
    functionName: "GetPointGoodDetailList",
    contentData: query,
  }).then((res) => {
    console.log("预点订查询yudian订单table res :>> ", res);
    loading.value = false;
    tableData.value = res.data.list;
    console.log(tableData.value, "tableData------------------");
    total.value = res.totalCount;
    console.log(res.data)
    headData2.value = res.data;
    // if (res.data.totalAmt && res.data.totalQty) {
      
    // }
  });
};

//  --------------------------------------------------------------- 初始化 ---------------------------------------------------------------------

//初始化
const onInit = async () => {
  GetGoodsTypeOrg();
  GetGoodsPoint();
};
onInit();

onMounted(() => {
  searchForm.value.operDate = transformWorkTime(
    "今天",
    orgStartTime,
    orgEndTime
  ); // 默认今天
  searchFormPre.value.operDate = transformWorkTime(
    "今天",
    orgStartTime,
    orgEndTime
  ); // 默认今天
  getTableData();
});

const doExport = (type)=>{
  console.log(type);
    const baseURL = import.meta.env.MODE == 'development' ? '/api/' : import.meta.env.VITE_BASE_API
    const USER_INFO = ls.get('USER_INFO')
    let query = {}
     // 调用
    let url = ''
    if(type == 'hz'){
      url = baseURL + 'PointGoodListExport/pointlistexport';
      query = {
          ...searchForm.value,
          orgName:'',
          pageSize:0,
          pageIndex:0,
          goodsName:'',
          goodsType:'',
          goodsCode:'',
          userName:'',
          goodsPoint:searchForm.value.goodsPoint ? searchForm.value.goodsPoint.join(',') : '',
          roomCode:'',
          areaCode:'',
          giveType:'',
          itemType:'',
          pointBase:[],
          orgCode:USER_INFO ? USER_INFO.orgCode : ''
      }
    }else{
      url = baseURL + 'PointGoodListDetailExport/pointlistdetailexport';
      query = {
          ...searchFormPre.value,
          orgName:'',
          pageSize:0,
          pageIndex:0,
          goodsName:'',
          goodsType:'',
          goodsCode:'',
          userName:'',
          goodsPoint:searchFormPre.value.goodsPoint ? searchFormPre.value.goodsPoint : '',
          roomCode:'',
          areaCode:'',
          code:'',
          giveType:'',
          itemType:'',
          orgCode:USER_INFO ? USER_INFO.orgCode : ''
      }
    }

    if (query.operDate && query.operDate.length > 1) {
        query.startTime = query.operDate[0]
        query.endTime = query.operDate[1]
    }
    console.log(query);
    // searchFormPre
    function downloadExcel(url, params) {
    // 使用 fetch 发起 POST 请求
        fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json;charset=utf-8' // 根据需要调整
            },
            body: JSON.stringify(params) // 将参数转换为 JSON 字符串
        })
        .then(response => {
            // 检查响应是否成功
            if (!response.ok) {
                throw new Error('网络响应不正常');
            }
            return response.blob(); // 将响应转换为 Blob
        })
        .then(blob => {
            // 检查 Blob 是否以 'PK' 开头
            const reader = new FileReader();
            reader.onload = function(event) {
                const arr = new Uint8Array(event.target.result);
                const header = arr.slice(0, 2);
                if (header[0] === 0x50 && header[1] === 0x4B) { // 0x50 0x4B 是 'PK'
                    // 创建下载链接
                    const url = URL.createObjectURL(blob);
                    const a = document.createElement('a');
                    a.href = url;
                    a.download = 'downloadedFile.xlsx'; // 设置下载文件名
                    document.body.appendChild(a);
                    a.click(); // 自动点击下载
                    URL.revokeObjectURL(url); // 释放 URL 对象
                    a.remove(); // 移除链接
                } else {
                    console.error('返回的数据不是有效的 Excel 文件');
                }
            };
            reader.readAsArrayBuffer(blob); // 读取 Blob 数据为 ArrayBuffer
        })
        .catch(error => {
            console.error('请求失败:', error);
        });
    }

   
    
    downloadExcel(url, query);
}
</script>

<style scoped lang="scss">
@import '@/styles/com_style_input.css';
/* 在这里编写组件的CSS样式 */
// .app-container {}
.search-form {
  width: 1520px;
  margin-bottom: 10px;
  ::v-deep {
    .el-form-item__label {
      line-height: 48px;
    }

    .el-input__wrapper {
      // width: 200px;
      height: 40px;
      background: #ffffff;
      border-radius: 8px;
    }

    .el-select__wrapper {
      height: 40px;
      background: #ffffff;
      border-radius: 8px;
      overflow: auto;
      // padding: 0px;
      .el-select__input{
        display: none;
      }
    }

    .el-checkbox {
      height: 40px;
    }

    .el-checkbox__inner {
      width: 20px;
      height: 20px;
      border: 2px solid #666666;
      border-radius: 4px;
      background: #f9f9f9;
    }

    .is-checked {
      .el-checkbox__label {
        color: #ff6a00;
      }

      .el-checkbox__inner {
        background: #f9f9f9;
      }

      .el-checkbox__inner {
        width: 20px;
        height: 20px;
        border: 2px solid #ff6a00;
        border-radius: 4px;
        // background: #FF6A00;
      }

      .el-checkbox__inner::after {
        border: 2px solid #ff6a00;
        border-left: 0;
        border-top: 0;
        left: 7px;
        top: 4px;
      }
    }
  }

  .action-btn-box {
    display: flex;

    button {
      width: 120px;
      height: 48px;
      line-height: 48px;
      background: #ffe566;
      border-radius: 8px;
      border: 0;
      font-size: 16px;
      color: #212121;
    }

    .reset-btn {
      background: #e6e6e6;
      color: #666666;
    }
  }
}

.table-box {
  padding: 20px;
  background: #ffffff;
  border-radius: 8px;
  width: 1520px;

  .total-box {
    display: flex;
    margin-bottom: 20px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    font-size: 20px;
    color: #212121;
    .content {
      margin-right: 60px;
    }
  }

  .el-table--fit {
    height: 400px;
  }

  ::v-deep {
    .el-table__inner-wrapper::before {
      height: 0px;
    }

    .el-table th {
      font-size: 13px;
      font-weight: 700;
    }

    .el-table .el-table__header th,
    .el-table .el-table__header tr,
    .el-table .el-table__header td {
      height: 48px;
      background: #f9f9f9;
    }
  }

  .action-btn {
    width: 66px;
    height: 28px;
    border-radius: 4px;
    border: 1px solid #ff6a00;
    font-family: Microsoft YaHei;
    font-weight: 400;
    font-size: 14px;
    color: #ff6a00;
  }
}

.pagination-box {
  margin-top: 20px;

  ::v-deep {
    .number {
      background: #e6e6e6 !important;
      border-radius: 8px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      font-size: 18px;
      color: #666666;
    }

    .number:hover {
      color: #ff6a00;
    }

    .is-active {
      background-color: #ff6a00 !important;
      border-radius: 8px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      font-size: 18px;
      color: #ffffff;
    }
  }
}

.color-FF6A00 {
  color: #ff6a00;
}
.consult-container {
  white-space: nowrap;

  .consult-tabs {
    display: flex;
    margin-bottom: 20px;
    .consult-tab {
      width: 300px;
      background: #ffffff;
      border-radius: 8px;
      border: 1px solid #e6e6e6;
      text-align: center;
      padding: 21px 0;
      margin-right: 40px;
      cursor: pointer;
      font-family: Microsoft YaHei;
      font-weight: 400;
      font-size: 18px;
      color: #666666;
      line-height: 18px;

      &.active {
        background: #ffd400;
        border: 1px solid #ffd400;
        color: #212121;
      }
    }
  }
  .consult-bewtten {
    width: 1520px;
    display: flex;
    justify-content: space-between;
  }
  .cp_continar {
    cursor: pointer;
    text-align: center;
    width: 180px;
    height: 60px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e6e6e6;
    text-align: center;
    line-height: 60px;
    font-size: 18px;
    color: #ff6a00;
  }
}
.page-title {
  font-family: Microsoft YaHei;
  font-weight: bold;
  font-size: 24px;
  color: #212121;
  margin-bottom: 10px;
}
::v-deep .table-box .el-table .cell {
  font-family: Microsoft YaHei;
  font-weight: 400;
  font-size: 0.07292rem;
  color: #666666;
  line-height: 0.07292rem;
}
::v-deep .el-form-item__label-wrap {
  margin-left: 0 !important;
}
.fl-item{
  ::v-deep{
    .el-select__wrapper{
      width: 200px;
    }
  }
}
.setup-main-item{
  // padding-left: 20px;
  border-radius: 8px;
  .item-right{
    padding: 10px;
    border-radius: 8px;
    background: #ffffff;
  }
  
}
.time-radio{
  margin-top: 7px;
  ::v-deep(.el-radio){
    height: 15px;
  }
}
::v-deep(.el-radio){
  margin-right: 14px;
}
::v-deep(.el-radio__inner) {
      // margin-left: 20px;
      width: 20px;
      height: 20px
    }

    ::v-deep(.el-radio__input.is-checked .el-radio__inner) {
      border-color: #ff6a00;
      /* 选中状态边框颜色 */
      background-color: #ffffff;
      /* 选中状态背景颜色 */
    }

    ::v-deep(.el-radio__inner:after) {
      background-color: #ff6a00;
      width: 8px;
      height: 8px;
    }

    ::v-deep(.el-radio__label) {
      font-family: Microsoft YaHei;
      font-weight: 400;
      font-size: 16px;
      color: #666666 !important;
      line-height: 16px;
    }
</style>
